package net.huashitong.scheduling.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import net.huashitong.scheduling.entity.TownProjectList;
import net.huashitong.scheduling.entity.TownRankList;
import net.huashitong.scheduling.filter.ProjectReserveFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class TownRankListDao extends StringDao<TownRankList> {

    public List<TownRankList> queryByMonthAndYear(String month, String year){
        GenericQuery query = createQuery("obj");
        query.append(" and obj.month = :month").setParam("month",month);
        query.append(" and obj.year = :year").setParam("year",year);
        return query.listResult();
    }

    public List<TownRankList> queryByfilter(ProjectReserveFilter filter){
        GenericQuery query = createQuery("obj");
        query.append(" and obj.month = :month").setParam("month",filter.getMonth());
        query.append(" and obj.year = :year order by cast(obj.percentage as int ) DESC ").setParam("year",filter.getYear());
        return query.listResult();
    }

    public TownRankList queryByfilterAndParentId(ProjectReserveFilter filter){
        GenericQuery query = createQuery("obj");
        query.append(" and obj.month = :month").setParam("month",filter.getMonth());
        query.append(" and obj.year = :year").setParam("year",filter.getYear());
        query.append(" and obj.parentId = :parentId").setParam("parentId",filter.getParentId());

        return query.singleResult();
    }

}
